export { BaseParser } from './BaseParser';
export { RowParser } from './parsers/RowParser';
export { RowListParser } from './parsers/RowListParser';
export { ColParser } from './parsers/ColParser';
export { SwitchParser } from './parsers/SwitchParser';
export { CheckboxParser } from './parsers/CheckboxParser';
export { RadioParser } from './parsers/RadioParser';
export { ProgressParser } from './parsers/ProgressParser';
export { SliderParser } from './parsers/SliderParser';
export { SwiperParser } from './parsers/SwiperParser';
export { IconParser } from './parsers/IconParser';
export { TabsParser } from './parsers/TabsParser';
export { NoopParser } from './parsers/NoopParser';

import { ParserFactory } from './ParserFactory';

const parsers: Record<string, ReturnType<typeof ParserFactory.create>> = {};

export type ParseWxTagsFunc = (nodes: any[]) => void

function parse(node: any, recurse?: ParseWxTagsFunc) {
    let name = node.name;
    if (name) {
        let parser = parsers[name];
        if (!parser) {
            parser = ParserFactory.create(name, recurse);
        }
        parser.parse(node);
    }
}

export const parseWxTags = (nodes: any[]) => {
    nodes.forEach((node) => {
        if (node.name === 'ui-row') {
            parse(node);
            node.children.forEach((childNode: any) => {
                if (childNode.name === 'ui-col') {
                    parse(childNode, parseWxTags);
                }
            });
        }
        else {
            parse(node);
        }
        if (node.children) {
            parseWxTags(node.children);
        }
    });
};
